﻿/************************************************************************
 * SMLib - State Model Library
 * Copyright (C) 2012-2013 Ali Khalili (khalili_DOT_ir_@SIGN_gmail_DOT_com)
 * **********************************************************************
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License (LGPL) published 
 * by the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version. This program is distributed without any
 * warranty. See the GNU Lesser General Public License for more details. 
 * ***********************************************************************
 * File         :     
 * Description  :     
 * Change log   :     
 * To Do        :
 ************************************************************************/
using System;
using System.Collections.Generic;
using SMLib.Automata.Base;

namespace SMLib.Automata.Moore
{
    /// <summary>
    /// Construct a Moore Machine
    /// </summary>
    public class MooreConstructor
    {
        MooreMachine machine;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="inputAlph">the input alphabet</param>
        /// <param name="outAlph">the output alphabet</param>
        public MooreConstructor(Alphabet inputAlph, Alphabet outAlph)
        {
            machine = new MooreMachine(inputAlph, outAlph);
        }

        public MooreMachine.Moore_State State(int index)
        {
            if (machine.Size > index)
                return machine[index];
            else
                return null;
        }


        public MooreMachine.Moore_State AddState(string ID, ISymbol output)
        {
            MooreMachine.Moore_State st = new MooreMachine.Moore_State(ID, output);
            machine.AddState(st);
            return st;
        }

        public bool AddTransition(MooreMachine.Moore_State src, ISymbol input, MooreMachine.Moore_State dest)
        {
            src.AddTransition(dest, input);
            return true;
        }

        public MooreMachine Machine
        {
            get
            {
                return machine;
            }
        }
    }
}
